%a MenuItemName of '' will not add anything to the list of the menu's items, but will add the menu to the list of menus if necessary.
%always use 'set' or 'delete' for the first argument.
%enter 'standard' or 'hierarchical' for the kind field.
%Enter 'enabled' or 'disabled' or '' in the Enable field.
%Enter Icon Number or 0 in Icon Field
%Enter character code for Keyboard Equivalent in KeyEquivalent Field (only works for a new menu).
%Enter character code for Marking Character in MarkChar Field.
%Menu Number & Item Number are returned.
'system$menu' can be used to enable & disable existing menu items.
The system adds 256 to the icon number you provide, if it's not 0.
(Supply your own icons using something like ResEdit.)
example:
J is "",K is "Y",'system$menu'(set,'Trixi','First Menu 2',standard,enabled,1,K,J,Menu,Item).
SUGGESTION - set the font for this window to Chicago (the standard menu bar font), and experiment with different values for J above (look in KeyCaps for reference - e.g. control-R gives the tick mark ).
When the menu is selected by the user, Open Prolog looks for a clause
with a head of the form:
'system$menu$hook'(MenuName,MenuItemName)
If it is found, the clause is executed.
í Hierarchical Menus
The Command Key field and the Mark Char field are re-used to implement hierarchical menus. To hook up hierarchical menus, the Markchar number of the menu item that points to the hierarchical menus must be the same as the hierarchical menu's Menunumber. So, you can define the hierarchical menu items first, getting back the menu's menunumber; then define the menu item that points to it as a hierarchical menu pointer (by making its command character number 27), and 'hook it up' to the previously defined hierarchical menu by defining its markchar number to be the same as the hierarchical menu's number. Complicated huh?
Notice that when a hierarchical menu item is selected, it is the *menu's* name and the menu item name that are returned - see the example below.
Here's an example that also demonstrates the 'system$menu$hook'. Select it all and press the ENTER key:
If the MenuItem is '', the whole menu is deleted. Be careful about deleting the standard menus - they are linked to Open Prolog by position, not by text or appearance.
For some special purposes, you may wish to delete the Prolog menu; that's fine, but you'd also be deleting the command-(.) menu item which is used for stopping wayward program execution. You can redefine the command-(.) menu item to suit your own purposes, as long as you make sure its command key equivalent is the dot.
Ñ Status Bar
The status bar is available to your program as a convenient display for the state of your program. Users are happier when they know something is happening. The rotating cursor indicates that Open Prolog is running, and you can get your program to display ongoing information on the status bar.
There are three resources available to your program:
(1) The status box at the extreme left - normally it contains the prompt ?-; occasionally it contains 'mm' or 'gc' indicating memory management or garbage collection activity.
(2) The message box, from the right hand side of the window leftwards. This may contain a larger string of text.
(3) The progress indicator. This is a 'thermometer' - a rectangle in which you can set the fraction of it showing gray. You see this when consulting a file.
You can push, set (i.e. change) or pull messages to or from the status and message boxes, and you can show, hide and set the progress indicator.
'system$set$progress'(A,B). % set gray part of thermometer as a fraction of the rectangle equal to the ratio A/B.
Previous values of A and B are lost.
Note: if your application's execution is characterised by processing a file, then by using the 'system$get$file$size' and 'system$get$fpos' predicates (see below) in conjunction with the progress indicator, you can give the user an idea of how much progress is being made. Here is an example where calls to the get0 predicate could be replaced by get0WithProgress:
get0WithProgress(X) :-
seeing(user),!, %don't display for input from the user╔
%returns in FileSize the size of FileName in bytes. (Normally one character occupies one byte.) An ErrorNumber of 0 is OK, anything else is a problem. Note that it isn't necessarily possible to open the file.
These are the characters returned by get or get0 for an end-of-line condition of an end-of-file condition, chosen for compatibility with DEC10 Prolog.
Ñ Window-handling Predicates.
A number of predicates have been written to handle window-based I/O.
Please be aware that they are subject to change.
Basic Ideas:
í Window Numbers
We use window numbers because it is not possible to refer to a window by its name. This is because its name may change, and because (in theory anyway) many windows could have the same names.
So, every window is assigned a window number when it is created (distinct from its parameter pointer or file number etc.).
í Starting Pointer & Single-Line-Selection
Whenever text is output to a window (say using the write command), a pointer, called the Starting Pointer, is made point to the next character after the last
character output.
When a user selects text using the ENTER key, the text selected goes
into a text buffer that is passed to the Prolog interpreter.
In the case of single-line-selection, the start of the selection is found by going from the caret backwards along the line to the start of the line or to the Starting Pointer, whichever comes first. The end of the selection is the end of the line.
í Highlighting & Outlines
It is possible to highlight a particular run of text. Just to confuse you,
the highlight is called an outline, because that's how it started out.
The highlight will 'stick' to the text specified even when text before,
within or after it has been added or removed. Therefore it's not safe to
refer to a highlight by its start & end points, which may vary. Instead, a
highlight is given a unique index number by which it may be referred to